SQL グループごとにN件出力する
SQLで「グループごとにn件出力する」というSELECT文を書く - 漆黒な技術メモ
以下は各グループの列を2件ずつ表示するSQL
code: SQL
select * from table as t1
where id in
(select id from table as t2 where t1.ssid=t2.ssid and status='ON' order by id desc limit 2)
order by ssid, id desc;